$(function(){
		$("#studentid").mouseleave(function(){
			var reg= /^[0-9]\d{10}$/
			var studentid=$("#studentid").val();
			if(!reg.test(studentid)){
				$("#stup1").css("color","red");
				$("#stup1").html("*请正确输入您的学号");
			}else{
				$("#stup1").css("color","black");
				$("#stup1").html("*");
			}
		})
		$("#phonenumber").mouseleave(function(){
			var phonenumber=$("#phonenumber").val();
			var reg= /^1\d{10}$/
			if(!reg.test(phonenumber)){
				$("#stup6").css("color","red");
				$("#stup6").html("*请输入正确的手机号");
			}else{
				$("#stup6").css("color","black");
				$("#stup6").html("*");
			}
		})
		$("#scoolname").mouseleave(function(){
			if($("#scoolname").val()==""){
				$("#stup3").css("color","red");
				$("#stup3").html("*学校名不能为空");
			}else{
				$("#stup3").css("color","black");
				$("#stup3").html("*");
			}
		})
		$("#name").mouseleave(function(){
			if($("#name").val()==""){
				$("#stup4").css("color","red");
				$("#stup4").html("*姓名不能为空");
			}else{
				$("#stup4").css("color","black");
				$("#stup4").html("*");
			}
		})
		$("#address").mouseleave(function(){
			if($("#address").val()==""){
				$("#stup7").css("color","red");
				$("#stup7").html("*地址不能为空");
			}else{
				$("#stup7").css("color","black");
				$("#stup7").html("*");
			}
		})
		
		
			$("#btn").click(function () {
				if($(".p").css('color')=="rgb(0, 0, 0)"){
					if($("#password").val()==""){
		        		alert("密码不能为空")
		        	}else{
		        		if($("#password").val()==$("#passwordtwo").val()){
		           		 $.ajax({
		                        url:"http://localhost:8080/reference/info/register",
		                        type:"POST",
		                        dataType:"json", 
		                        data:{"studentid":$("#studentid").val(),
		                       	 	"password":$("#password").val(),
		                       		"scoolname":$("#scoolname").val(),
		                       	 	"name":$("#name").val(),
		                       	 	"sex":$('input[name="sex"]:checked').val(),
		                       	 	"phonenumber":$("#phonenumber").val(),
		                       	 	"address":$("#address").val(),
		                       	 	"charcode":$("#codes").val()},
		                       success: function(data){
		                       	//需要解析成字符串格式
		                       	//var re=JSON.stringify(result);
		                       	
		                       	if(data.result=="success"){
		                       		window.location.href="http://localhost:8080/reference/login/"
		                       		alert("注册成功")
		                       	}else if(data.result=="error"){
		                       		alert("账号已被占用")
		                       	}else{
		                       		alert("网络错误")
		                       	}
		                    	  return false;
		                       }
		                    
		                    });
		           	}else{
		           		alert("两次密码不一致")
		           	}
		        	}
				}else{
//					alert($(".p").css('color'))
				}
	        	
	        });
        
		
			
});